﻿namespace Chain.BLL
{
    using Chain.IDAL;
    using Chain.Model;
    using System;
    using System.Collections.Generic;
    using System.Data;

    public class WeiXinMenu
    {
        private readonly Chain.IDAL.WeiXinMenu dal = new Chain.IDAL.WeiXinMenu();

        public int Add(Chain.Model.WeiXinMenu model)
        {
            return this.dal.Add(model);
        }

        public List<Chain.Model.WeiXinMenu> DataTableToList(DataTable dt)
        {
            List<Chain.Model.WeiXinMenu> list = new List<Chain.Model.WeiXinMenu>();
            int count = dt.Rows.Count;
            if (count > 0)
            {
                for (int i = 0; i < count; i++)
                {
                    Chain.Model.WeiXinMenu item = new Chain.Model.WeiXinMenu();
                    if ((dt.Rows[i]["MenuID"] != null) && (dt.Rows[i]["MenuID"].ToString() != ""))
                    {
                        item.MenuID = int.Parse(dt.Rows[i]["MenuID"].ToString());
                    }
                    if ((dt.Rows[i]["MenuName"] != null) && (dt.Rows[i]["MenuName"].ToString() != ""))
                    {
                        item.MenuName = dt.Rows[i]["MenuName"].ToString();
                    }
                    if ((dt.Rows[i]["MenuType"] != null) && (dt.Rows[i]["MenuType"].ToString() != ""))
                    {
                        item.MenuType = int.Parse(dt.Rows[i]["MenuType"].ToString());
                    }
                    if ((dt.Rows[i]["MenuKey"] != null) && (dt.Rows[i]["MenuKey"].ToString() != ""))
                    {
                        item.MenuKey = dt.Rows[i]["MenuKey"].ToString();
                    }
                    if ((dt.Rows[i]["MenuUrl"] != null) && (dt.Rows[i]["MenuUrl"].ToString() != ""))
                    {
                        item.MenuUrl = dt.Rows[i]["MenuUrl"].ToString();
                    }
                    if ((dt.Rows[i]["parentMenuID"] != null) && (dt.Rows[i]["parentMenuID"].ToString() != ""))
                    {
                        item.parentMenuID = int.Parse(dt.Rows[i]["parentMenuID"].ToString());
                    }
                    list.Add(item);
                }
            }
            return list;
        }

        public bool Delete(int MenuID)
        {
            return this.dal.Delete(MenuID);
        }

        public bool DeleteList(string MenuIDlist)
        {
            return this.dal.DeleteList(MenuIDlist);
        }

        public bool Exists(int MenuID)
        {
            return this.dal.Exists(MenuID);
        }

        public DataSet GetAllList()
        {
            return this.GetList("");
        }

        public DataSet GetList(string strWhere)
        {
            return this.dal.GetList(strWhere);
        }

        public DataSet GetList(int Top, string strWhere, string filedOrder)
        {
            return this.dal.GetList(Top, strWhere, filedOrder);
        }

        public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
        {
            return this.dal.GetListByPage(strWhere, orderby, startIndex, endIndex);
        }

        public DataSet GetMenuAllInfo()
        {
            return this.dal.GetMenuAllInfo();
        }

        public DataSet GetMenuAllInfo2()
        {
            return this.dal.GetMenuAllInfo2();
        }

        public DataSet GetMenuChildInfo(int parentMenuID)
        {
            return this.dal.GetMenuChildInfo(parentMenuID);
        }

        public DataSet GetMenuParentInfo()
        {
            return this.dal.GetMenuParentInfo();
        }

        public Chain.Model.WeiXinMenu GetModel(int MenuID)
        {
            return this.dal.GetModel(MenuID);
        }

        public List<Chain.Model.WeiXinMenu> GetModelList(string strWhere)
        {
            DataSet list = this.dal.GetList(strWhere);
            return this.DataTableToList(list.Tables[0]);
        }

        public int GetRecordCount(string strWhere)
        {
            return this.dal.GetRecordCount(strWhere);
        }

        public int GetUseCountByRuleID(int RuleID)
        {
            return this.dal.GetUseCountByRuleID(RuleID);
        }

        public bool Update(Chain.Model.WeiXinMenu model)
        {
            return this.dal.Update(model);
        }

        public int UpdateMenuKey(string OldMenuKey, string NewMenuKey)
        {
            return this.dal.UpdateMenuKey(OldMenuKey, NewMenuKey);
        }
    }
}

